package com.foomia.truego.parsers.json;

import org.json.JSONException;
import org.json.JSONObject;

import com.foomia.truego.types.Geometry;
import com.foomia.truego.types.Types;
import com.foomia.truego.types.Venue;


public class VenueParser  extends AbstractParser<Venue>{
	@Override
    public Venue parse(JSONObject json) throws JSONException {

        Venue obj = new Venue();
        if (json.has("icon")) {
            obj.setIcon(json.getString("icon"));
        } 
        if (json.has("id")) {
            obj.setId(json.getString("id"));
        } 
        if (json.has("name")) {
            obj.setName(json.getString("name"));
        } 
        if (json.has("types")) {
            obj.setTypes(
            		new Types(StringArrayParser.parse(json.getJSONArray("types"))));
        } 
		if (json.has("geometry")) {
			Geometry geometry = new GeometryParser().parse(json
					.getJSONObject("geometry"));
			obj.setGeolat(geometry.getLat());
			obj.setGeolong(geometry.getLng());
		}
        if (json.has("reference")) {
            obj.setReference(json.getString("reference"));
        }
        if (json.has("vicinity")) {
            obj.setAddress(json.getString("vicinity"));
        }
        if (json.has("url")) {
            obj.setURL(json.getString("url"));
        }
        return obj;
    }

}
